package one.stand.controller;

import com.jmp.autocofiguration.web.interceptor.SecurityAuthCheck;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import one.stand.mapper.CompanyAccountMapperExt;
import one.stand.model.CompanyAccountModel;
import one.stand.model.ResultModel;
import one.stand.request.CompanyAccountRequest;
import one.stand.response.CompanyAccountResponse;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: QIK
 * @CreateDate: 2019/5/13 17:29
 */
@RequestMapping("crmPc/companyAccount")
@RestController
@Api(description = "小程序账号信息")
public class CompanyAccountController extends BaseController {

    @Autowired
    private CompanyAccountMapperExt companyAccountMapperExt;

    @ApiOperation(value = "获取小程序账号列表")
    @PostMapping("getCompanyAccountList")
    @SecurityAuthCheck(company = true, card = true)
    public ResultModel<List<CompanyAccountResponse>> getCompanyAccountList(@RequestAttribute CompanyAccountRequest request) {
        List<CompanyAccountModel> list = companyAccountMapperExt.selectList(new CompanyAccountModel() {{
            setCompanyId(request.getCId().intValue());
        }});
        List<CompanyAccountResponse> responseList = new ArrayList<>();
        list.forEach(l -> {
            CompanyAccountResponse response = new CompanyAccountResponse();
            BeanUtils.copyProperties(l, response);
            responseList.add(response);
        });
        return ResultModel.success(responseList);
    }
}
